<template>
  <div class="navbar">
    <div class="title">
      <el-image 
        v-if="false" 
        class="title-img"
        src="http://codegen.caihongy.cn/20201114/7856ba26477849ea828f481fa2773a95.jpg" 
        fit="cover" 
      />
      <span class="title-name">{{this.$project.projectName}}</span>
    </div>
    <div class="right">
      <div class="user-info">
        <i class="el-icon-user user-icon"></i>
        <span class="nickname">{{this.$storage.get('role')}} {{this.$storage.get('adminName')}}</span>
      </div>
      <div class="btn-group">
        <div v-if="this.$storage.get('role')!='管理员'" class="btn btn-index" @click="onIndexTap">
          <i class="el-icon-s-home"></i>
          <span>前台首页</span>
        </div>
        <div class="btn btn-logout" @click="onLogout">
          <i class="el-icon-switch-button"></i>
          <span>退出登录</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
	export default {
		data() {
			return {
				dialogVisible: false,
				ruleForm: {},
				user: {},
			};
		},
		created() {
			
		},
		mounted() {
			let sessionTable = this.$storage.get("sessionTable")
			this.$http({
				url: sessionTable + '/session',
				method: "get"
			}).then(({
				data
			}) => {
				if (data && data.code === 0) {
					this.user = data.data;
					this.$storage.set('userid',data.data.id);
				} else {
					let message = this.$message
					message.error(data.msg);
				}
			});
		},
		methods: {
			onLogout() {
				let storage = this.$storage
				let router = this.$router
				storage.clear()
				router.replace({
					name: "login"
				});
			},
			onIndexTap(){
				window.location.href = `${this.$base.indexUrl}`
			},
		}
	};
</script>

<style lang="scss" scoped>
.navbar {
  width: 100%;
  height: 64px;
  background: linear-gradient(135deg, #1890ff 0%, #1d39c4 100%);
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  box-sizing: border-box;
  
  .title {
    display: flex;
    align-items: center;
    height: 100%;
    
    .title-img {
      width: 40px;
      height: 40px;
      border-radius: 8px;
      object-fit: cover;
      margin-right: 16px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    .title-name {
      font-size: 22px;
      font-weight: 600;
      color: #fff;
      letter-spacing: 1px;
      text-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
  }
  
  .right {
    display: flex;
    align-items: center;
    gap: 24px;

    .user-info {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 12px;
      background: rgba(255,255,255,0.1);
      border-radius: 20px;

      .user-icon {
        font-size: 18px;
        color: #fff;
      }

      .nickname {
        color: #fff;
        font-size: 14px;
      }
    }

    .btn-group {
      display: flex;
      gap: 12px;

      .btn {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 16px;
        border-radius: 20px;
        cursor: pointer;
        transition: all 0.3s;
        font-size: 14px;
        color: #fff;

        i {
          font-size: 16px;
        }

        &:hover {
          transform: translateY(-1px);
        }
      }

      .btn-index {
        background: rgba(255,255,255,0.2);

        &:hover {
          background: rgba(255,255,255,0.3);
        }
      }

      .btn-logout {
        background: rgba(255,255,255,0.1);

        &:hover {
          background: rgba(255,255,255,0.2);
        }
      }
    }
  }
}
</style>
